//
//  YunCamHttp.h
//  p2pcam264
//
//  Created by tutk on 3/23/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//


enum SERVER_CMD{
    CMD_CMDINF_CODE             = 1000,  //命令字码
    CMD_REG_CODE				= 1001,  //注册命令码
    CMD_RANDOM_CODE             = 1002,  //请求登录验证码命令码
    CMD_LOGIN_CODE              = 1003,  //登录命令码
    CMD_ALIVE_CODE              = 1004,  //刷新登录时效
    CMD_FINDPW_CODE             = 1005,  //找回密码命令码
    CMD_SETPW_CODE              = 1006,  //设置密码命令码
    CMD_SETMAIL_CODE            = 1007,  //重设邮箱命令码
    CMD_SHOWMAIL_CODE           = 1008,  //查看注册邮箱命令码
    CMD_ADDDEV_CODE             = 1009,  //添加设备命令码
    CMD_UPDATEDEV_CODE          = 1010,  //更新设备参数命令码
    CMD_DELDEV_CODE			= 1011,  //删除设备命令码
    CMD_SELECTDEV_CODE	= 1012,  //查找设备信息命令码
    CMD_REGALARM_CODE		= 1013,  //手机注册报警命令码(向服务器注册后才可正常接收报警推送)
    
    CMD_LOGOUT_CODE		= 1014,  //退出登录
    /*宠物相关的协议命令*/
    CMD_BINDNEWPET_CODE	= 1015,  //设备绑定新的宠物信息
    CMD_BINDPETID_CODE		= 1016,  //设备绑定已有宠物信息
    CMD_UNBINDPET_CODE		= 1017,  //设备解绑宠物信息
    CMD_MODIYPET_CODE		= 1018,  //修改宠物信息
    CMD_DELETEPET_CODE	= 1019,  //删除宠物信息
    CMD_PETLIST_CODE		= 1020,  //请求宠物信息列表
    CMD_DAYFEED_CODE		= 1021,  //请求每天喂食信息
    CMD_WEEKFEED_CODE		= 1022,  //请求最近一周喂食信息
    
    CMD_ISBIND_CODE			= 1100,  //查询设备是否被添加了
    CMD_UPLOADPIC_CODE		= 1101,  //设备上传报警图片命令码
    CMD_RAISEALARM_CODE	= 1102  //设备推送报警命令码
};
    
//服务器返回给APP的信息自定义编码：
enum SERVER_RET{
    RET_SUCCESS				= 20000, //服务器操作成功
    RET_FAILURE					= 20001, //服务器操作失败
    RET_INF_ABNORMAL		= 20002, //APP提交请求信息异常
    RET_CONN_FAILURE			= 20003, //服务器连接数据库失败
    RET_DEVID_ABNORMAL		= 20004, //设备ID号异常
    RET_PHONE_ABNORMAL      = 20005, //手机号无效
    RET_MAIL_ABNORMAL       = 20006, //邮箱地址无效
    
    
    /*特有返回码*/
    /*查询手机是否已注册*/
    RET_CHECKPHONE_UNTOKEN  = 20801, //手机未被注册
    RET_CHECKPHONE_TOKEN    = 20802, //手机已被注册
    
    /*查询手机是否已注册*/
    RET_CHECKREGED_UNTOKEN  = 20901, //未被注册
    RET_CHECKREGED_TOKEN    = 20902, //已被注册

    
    /*请求登录验证码:212xx*/
    
    RET_RANDOM_NO_USERID    = 21201, //用户ID没注册
    
    /*注册新用户：211xx*/
    RET_RG_MAIL_INVALID     = 21101, //邮箱地址无效
    RET_RG_USERID_TOKEN     = 21102, //注册ID 已被占用
    RET_RG_MAIL_TOKEN       = 21103, //注册邮箱已注册
    RET_RG_PHONE_TOKEN      = 21104, //手机已注册过
    RET_RG_RND_ERROR        = 21105, //手机验证码错误
    
    
    /*登录:213xx*/
    RET_ID_PW_WRONG	= 21301, //密码错误
    
    /*刷新登录时效:214xx*/
    RET_REFLASH_ALIVE_INVALID     = 21401, //登录失效
    
    /*找回密码:215xx*/
    RET_FINDPW_NO_MAIL_RECORD = 21501, //找回密码填写的 邮箱没记录
    RET_FINDPW_TOO_OFTEN = 21502, // 找回密码太频繁，1 分钟后再申请
    RET_FINDPW_MAIL_INVALID = 21503, //邮箱格式不正确
    
    /*设置密码:216xx*/
    RET_OLD_PASSWD_ERROR          = 21601, //设置密码输入的原密码不正确
    
    /*重设邮箱*/
    RET_SETMAIL_PW_ERROR	= 21701, //重设邮箱的密码不正确
    
    /*查看注册邮箱:218xx*/
    RET_SHOWMAIL_NO_USERID_RECORD = 21801,  //查看邮箱的用户名没注册
    
    /*添加设备:219xx*/
    RET_ADDDEV_NO_USERID_RECORD   = 21901, //添加设备的用户名没注册
    RET_ADDDEV_DEVID_TOKEN        = 21902, //设备已被添加
    RET_ADDDEV_ADDED              = 21903, //设备已在账号名下

    /*更新设备:220xx*/
    RET_UPDATE_NO_RECORD          = 22001, //更新设备无记录
    
    /*删除设备:221xx*/
    RET_DELETE_NO_RECORD          = 22101, //删除设备无记录
    
    /*查询设备:222xx*/
    RET_SELECT_NO_RECORD          = 22201, //查询设备无记录
    
    /*注册报警:223xx*/
    RET_REGALARM_NO_USERID_RECORD = 22301, //注册报警的用户名没注册
    
    
    /*退出登录:224xx*/
    RET_LOGOUT_NO_USERID_RECORD   = 22401, //退出登录用户名没注册
    
    /*绑定新的宠物信息:225xx*/
    RET_BINDNEWPET_NO_USERID_RECORD   = 22501, //绑定新宠物信息的用户名没注册
    RET_BINDNEWPET_BINDED 	  = 22502, //设备已经有绑定的宠物
    
    /*绑定已有的宠物信息:226xx*/
    RET_BINDPETID_NO_USERID_RECORD    = 22601, //绑定已有宠物信息的用户名没注册
    
    /*解除设备绑定的宠物:227xx*/
    RET_UNBINDPET_NO_USERID_RECORD    = 22701, //解除绑定设备中宠物的用户名没注册
    
    /*编辑宠物信息:228xx*/
    RET_MODIFYPET_NO_USERID_RECORD    = 22801, //编辑宠物信息的用户名没注册
    
    /*删除宠物信息:229xx*/
    RET_DELETEPET_NO_USERID_RECORD    = 22901, //删除宠物信息的用户名没注册
    
    /*请求宠物信息列表:230xx*/
    RET_PETLIST_NO_USERID_RECORD  = 23001, //请求宠物信息列表的用户名没注册
    
    /*请求宠物当天的喂养信息:231xx*/
    RET_DAYFEED_NO_USERID_RECORD  = 23101, //请求宠物当天喂养信息的用户名没注册
    
    /*请求宠物当周的喂养信息:232xx*/
    RET_WEEKFEED_NO_USERID_RECORD = 23201, //请求宠物当周喂养信息的用户名没注册
    
    
    
    
    /*查询设备是否被绑定:300xx*/
    RET_ISBIND_BUSY               = 30001, //已被绑定
    RET_ISBIND_FREE               = 30002, //未被绑定
    
    /*上传图片:301xx*/
    RET_ULFILE_TYPE_WRONG         = 30101, //上传文件类型错误
    
    /*推送报警:302xx*/
    RET_RAISE_NO_USERID_RECORD    = 30201, //推送的设备没有被用户添加
    RET_RAISE_NO_TOKEN_RECORD     = 30202, //没找到对应的手机
    RET_RAISE_REC_EVENT_FAILURE   = 30203 //记录报警推送失败
};

#if 0
enum SERVER_CMD{
    CMD_CMDINF_CODE			= 1000,  //命令字码
    CMD_REG_CODE            = 1001,  //注册命令码
    CMD_RANDOM_CODE         = 1002,  //请求登录随机码命令码
    CMD_LOGIN_CODE			= 1003,  //登录命令码
    CMD_ALIVE_CODE			= 1004,  //刷新登录时效
    CMD_FINDPW_CODE			= 1005,  //找回密码命令码
    CMD_SETPW_CODE			= 1006,  //设置密码命令码
    CMD_SHOWMAIL_CODE		= 1007,  //查看注册邮箱命令码
    CMD_ADDDEV_CODE         = 1008,  //添加设备命令码
    CMD_UPDATEDEV_CODE      = 1009,  //更新设备参数命令码
    CMD_DELDEV_CODE			= 1010,  //删除设备命令码
    CMD_SELECTDEV_CODE      = 1011,  //查找设备信息命令码
    CMD_REGALARM_CODE		= 1012,  //手机注册报警命令码(向服务器注册后才可正常接收报警推送)
    CMD_UPLOADPIC_CODE		= 1013,  //设备上传报警图片命令码
    CMD_RAISEALARM_CODE     = 1014   //设备推送报警命令码
};
    
enum SERVER_RET{
    RET_SUCCESS				= 2000, //服务器操作成功
    RET_FAILURE             = 2001, //服务器操作失败
    RET_INF_ABNORMAL		= 2002, //APP提交请求信息异常
    RET_CONN_FAILURE        = 2003, //服务器连接数据库失败
    RET_MAIL_INVALID        = 2004, //APP提交邮箱地址无效
    RET_USERID_TOKEN        = 2005, //用户名已被注册
    RET_PASSWD_ERROR		= 2006, //登录密码错误
    RET_DEVID_ABNORMAL		= 2007, //设备ID号异常
    RET_DEVID_ADDED			= 2008, //设备已被占用，不能重复添加
    RET_NO_RECORD			= 2009, //查询无记录
    RET_NO_USERID_RECORD	= 2010, //报警推送没有用户ID记录
    RET_NO_TOKEN_RECORD     = 2011, //报警推送没找到TOKEN记录
    RET_REC_EVENT_FAILURE	= 2012, //记录推送报警事件到数据库失败
    RET_TYPE_WRONG			= 2013, //类型错误
    RET_ALIVE_INVALID       = 2014  //连接失效
};
#endif
    
@protocol CommonHttpDelegate;

@interface CommonHttp : NSObject {
    
    BOOL recvBool;
    
    BOOL isAlert;
}

@property (nonatomic, assign) id<CommonHttpDelegate> delegate;
@property BOOL recvBool;

@property (nonatomic, copy) NSString *encryptionSalt;
@property (nonatomic, copy) NSString *securityCode;

- (void)printfVar;

- (NSData *)reqHttpGetMode:(NSString *)url;
- (NSData *)reqHttp:(NSString *)url data:(NSData *)postData;
- (NSString *)md5:(NSString *)str;
- (BOOL)retValueShow:(NSInteger)cmd code:(NSInteger)code;

- (BOOL)urlContainIllegalString:(NSString *)str;
- (BOOL)urlContainIllegalString2:(NSString *)str;

@end

@protocol CommonHttpDelegate

- (void)httpReturnErrorPasswordOrAccount;

@end
